package com.hl.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.entity.SysCourseOrders;
import com.hl.sfzy.entity.SysCourses;
import com.hl.sfzy.mapper.SysCoursesMapper;
import com.hl.sfzy.pojo.Course;
import com.hl.sfzy.service.SysCoursesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ffc
 * @version 1.0
 * @description: TODO
 * @className: SysCoursesServiceImpl
 * @date 2024/7/13 13:17
 */

@Service("sysCoursesService")
public class SysCoursesServiceImpl implements SysCoursesService {
    @Autowired
    private SysCoursesMapper sysCoursesMapper;

    @Override
    public int add(SysCourses entity) {
        return sysCoursesMapper.insert(entity);
    }

    @Override
    public int edit(SysCourses entity) {
        return sysCoursesMapper.update(entity);
    }

    @Override
    public int remove(Integer id) {
        return sysCoursesMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return sysCoursesMapper.deleteBatch(ids);
    }

    @Override
    public List<SysCourses> find(SysCourses entity) {
        return sysCoursesMapper.select(entity);
    }

    @Override
    public SysCourses findById(Integer id) {
        return sysCoursesMapper.selectById(id);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, SysCourses entity) {
        PageHelper.startPage(pageNum,pageSize);
        List<SysCourses> list = sysCoursesMapper.select(entity);
        PageInfo<SysCourses> pageInfo = new PageInfo<>(list);
        HashMap<String,Object> map = new HashMap<>();
        map.put(CommonConstant.PAGE_LIST,list);
        map.put(CommonConstant.PAGE_TOTAL,pageInfo.getPages());
        map.put(CommonConstant.TOTAL,pageInfo.getTotal());
        return map;
    }

    @Override
    public List<SysCourses> findByCollation(Integer pageNum, Integer pageSize, Course course) {
        List<SysCourses> list = sysCoursesMapper.selectByCollation(course);
        return list;
    }
}
